///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#ifndef _INC_H_
#define _INC_H_

#include <MGL_config.h>

//////////////////////////////////////////////////////////////////////
#ifdef WIN32
//////////////////////////////////////////////////////////////////////
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <GL/glew.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <GL/glut.h>

//////////////////////////////////////////////////////////////////////
#elif defined(LINUX)
//////////////////////////////////////////////////////////////////////

#include <GL/glew.h>
#include <Cg/cg.h>
#include <Cg/cgGL.h>
#include <GL/freeglut.h>

#include <unistd.h>
#include <time.h>

//////////////////////////////////////////////////////////////////////
#endif
//////////////////////////////////////////////////////////////////////


void		checkForGLErrors();


//////////////////////////////////////////////////////////////////////
#if defined(DEBUG)
//////////////////////////////////////////////////////////////////////

#	include <stdio.h>
enum eConsoleColor
{
	CONSOLECOLOR_RESET,
	CONSOLECOLOR_WHITE,
	CONSOLECOLOR_RED,
	CONSOLECOLOR_GREEN,
	CONSOLECOLOR_BLUE,
	CONSOLECOLOR_BG,
	CONSOLECOLOR_RB,
	CONSOLECOLOR_RG,
	CONSOLECOLOR_WHITE2,
	CONSOLECOLOR_RED2,
	CONSOLECOLOR_GREEN2,
	CONSOLECOLOR_BLUE2,
	CONSOLECOLOR_BG2,
	CONSOLECOLOR_RB2,
	CONSOLECOLOR_RG2,
};

#if  defined(WIN32)
#define		DEBUG_SPRINTF	sprintf_s
#elif defined(LINUX)
#define		DEBUG_SPRINTF	snprintf
#endif

#if defined(WIN32)
#define ASSERT(arg1)				if (!(arg1) && (IsDebuggerPresent())) { printf("assert %s failed(%d) %s \n", #arg1, __LINE__, __FILE__);  {__asm int 3};}
#else
#include <assert.h>
#define ASSERT(arg1)				assert( arg1 )
#endif

#define		PAUSEON(arg)	if(arg)getchar();


#define		DEBUG_MESSAGEMAX_LENGTH		1048576
static char Debug_LogMsg[ DEBUG_MESSAGEMAX_LENGTH ];
void		Debug_LogFull( char* debugSourceFile, int line, char* debugMsg );
void		Debug_Error	 ( char* debugMsg );
void		Debug_Warning( char* debugMsg );
void		Debug_Glitch ( char* debugMsg );
void		Debug_ChangeColor( eConsoleColor c );
void		Debug_OSPrint(  char* debugMsg );

#	define DEBUGCODE(code)			code
#	define DEBUG_OUT(...)			{ DEBUG_SPRINTF(Debug_LogMsg, DEBUG_MESSAGEMAX_LENGTH, __VA_ARGS__ ); Debug_OSPrint( Debug_LogMsg );							} 
#	define DEBUG_ERR(...)			{ DEBUG_SPRINTF(Debug_LogMsg, DEBUG_MESSAGEMAX_LENGTH, __VA_ARGS__ ); Debug_Error( Debug_LogMsg );								} 
#	define DEBUG_WAR(...)			{ DEBUG_SPRINTF(Debug_LogMsg, DEBUG_MESSAGEMAX_LENGTH, __VA_ARGS__ ); Debug_Warning( Debug_LogMsg );							} 

#ifdef WIN32
	#define DEBUG_LOG(...)			{ DEBUG_SPRINTF(Debug_LogMsg, DEBUG_MESSAGEMAX_LENGTH, __VA_ARGS__ ); Debug_LogFull( __FUNCTION__ , __LINE__, Debug_LogMsg );	} 
#else //WIN32
	#define DEBUG_LOG(...)			{ DEBUG_SPRINTF(Debug_LogMsg, DEBUG_MESSAGEMAX_LENGTH, __VA_ARGS__ ); Debug_LogFull( "", 0, Debug_LogMsg );	} 
#endif //WIN32


#define	GL_CHECK_ERRORS		checkForGLErrors

//////////////////////////////////////////////////////////////////////
#else
//////////////////////////////////////////////////////////////////////

#	define ASSERT(arg1)

#	define		PAUSEON(arg)	arg;

#	define DEBUGCODE(code)
#	define DEBUG_OUT(...)
#	define DEBUG_ERR(...)
#	define DEBUG_WAR(...)
#	define DEBUG_LOG(...)

#define	GL_CHECK_ERRORS		checkForGLErrors

//////////////////////////////////////////////////////////////////////
#endif
//////////////////////////////////////////////////////////////////////

#define			ABS(x)		( x < 0 ? -x : x )
#define			MAX(x,y)	( x > y ? x : y )
#define			MIN(x,y)	( x > y ? y : x )
#define			SGN(x)		( x >= 0 ? 1 : -1 )

#define			MGL_NEW			new
#define			MGL_DEL			delete
#define			SAFE_DEL(x)		{if(x){MGL_DEL x;x = NULL;}}
#define			SAFE_DEL_ARRAY(x)		{if(x){MGL_DEL[] x;x = NULL;}}

#define			MGL_PI			3.1415926535897932384626433832795f


#define			u8				unsigned char
#define			u16				unsigned short
#define			u32				unsigned int
#define			u64				unsigned long
#define			s8				char
#define			s16				short
#define			s32				int
#define			s64				long
#define			f32				float
#define			f64				double

void	SetVSync(bool);

float	oglVersion();

bool	MGL_init();
void	MGL_exit();

#endif	//inc.h
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
